﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.BusinessObjects;

public partial class Admin_FinSav_FinSav001 : AdminBasePage
{
    public bool canEdit = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["c"] != null && Request.QueryString["c"] == "1")
        {
            canEdit = true;
        }
        if (!IsPostBack)
        {
           
        }
    }

    protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
    {
        FinReceiptQuery q1 = new FinReceiptQuery("q1");

        TSCodeTableQuery q2 = new TSCodeTableQuery("q2");
        TSCodeTableQuery q3 = new TSCodeTableQuery("q3");
        TSCodeTableQuery q4 = new TSCodeTableQuery("q4");
        TSCodeTableQuery q6 = new TSCodeTableQuery("q6");
        BFThirdUnitQuery q5 = new BFThirdUnitQuery("q5");
        BFCompanyDicQuery q7 = new BFCompanyDicQuery("q7");
        VReceiptExtInfoQuery q8 = new VReceiptExtInfoQuery("q8");

        TSCodeTableQuery q9 = new TSCodeTableQuery("q9");

        q1.LeftJoin(q9).On(q1.VoucherDescription == q9.Code);

        q1.LeftJoin(q2).On(q1.FunctionDept == q2.Code);
        q1.LeftJoin(q3).On(q1.StorageStatus == q3.Code);
        q1.LeftJoin(q4).On(q1.DocumentsType == q4.Code);
        q1.LeftJoin(q5).On(q1.StorageLocation == q5.ThirdUnitID);
        q1.LeftJoin(q6).On(q1.Division == q6.Code);
        q1.LeftJoin(q7).On(q1.CompanyCode == q7.CompanyCode);
        q1.LeftJoin(q8).On(q1.ReceiptID == q8.ReceiptID);

        q1.SelectAll().Select(q2.Value1.As("FunctionDeptStr"), q3.Value1.As("StorageStatusStr"), q4.Value1.As("DocumentsTypeStr"), q5.Name.As("StorageLocationStr"), q6.Value1.As("DivisionStr"), q7.CompanyName, q7.CompanyCode, q8.SupplierBoxNo, q8.BoxNo, q9.Value1.As("DocDesc"));

        

        q1.Where(q1.IsSAP == 1 && q1.CreatedBy == LoginUserInfo.CurrentUser.LoginName).OrderBy(q1.CreatedDttm.Descending);
        q1.es.Top = 500;

        DataTable tableSorce = q1.LoadDataTable();
        pageGrid.DataSource = tableSorce;
        pageGrid.CurrentPage = e.NewPageIndex;
        pageGrid.DataBind();
    }

    protected string GetActionUrl(string status, object rowView, string boxNo, bool isSAP)
    {
        string retUrl = "";

        if (!canEdit)
        {
            return "";
        }

        if (status != ConstantValue.StorageStatusCode.Loan && status != ConstantValue.StorageStatusCode.PendingTransfer && status != ConstantValue.StorageStatusCode.Transfer && string.IsNullOrEmpty(boxNo))
        {
            retUrl = GetUpdateLink("FinSav001a.aspx", rowView, 700, 680, FinReceiptMetadata.ColumnNames.ReceiptID);

            if (!isSAP)
            {
                retUrl += "   " + GetLink("删除", "D", "FinSav001a.aspx", rowView, 700, 680, false, FinReceiptMetadata.ColumnNames.ReceiptID);
            }

        }

        return retUrl;
    }


}